package com.example.yin.controller;

import com.alibaba.fastjson.JSON;
import com.example.yin.Constants.Constants;
import com.example.yin.dao.SingerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@RestController
public class SingerController {
    @Autowired
    private SingerMapper singerMapper;

    @Configuration
    public class MyPicConfig implements WebMvcConfigurer {
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            String os = System.getProperty("os.name");
            if (os.toLowerCase().startsWith("win")) { // windos系统
                registry.addResourceHandler("/img/singerPic/**")
                        .addResourceLocations("file:" + Constants.RESOURCE_WIN_PATH + "\\img\\singerPic\\");
            } else { // MAC、Linux系统
                registry.addResourceHandler("/img/songListPic/**")
                        .addResourceLocations("file:" + Constants.RESOURCE_MAC_PATH + "/img/singerPic/");
            }
        }
    }

    @GetMapping(value = "/singer")
    public String name()
    {
        return JSON.toJSONString(singerMapper.selectList(null));
    }
}
